package tech.aistar.clothesspringboot.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.aistar.clothesspringboot.mapper.ClothesMapper;
import tech.aistar.clothesspringboot.pojo.Clothes;
import tech.aistar.clothesspringboot.service.ClothesService;
import tech.aistar.clothesspringboot.pojo.ClothesStock;


import java.util.List;

@Service
public class ClothesServiceImpl implements ClothesService {



    @Autowired
    private ClothesMapper clothesMapper;

    @Override
    public List<Clothes> getClothesList() {
        return clothesMapper.getClothesList();
    }

    //根据名字查询衣服信息
    @Override
    public List<Clothes> getClothesByName(String name) {
        return clothesMapper.getClothesByName(name);
    }

    //根据id查询衣服信息
    @Override
    public Clothes getClothesById(Integer id) {
        return clothesMapper.getClothesById(id);
    }
    //根据id查询库存
    @Override
    public List<ClothesStock> getStockById(Integer id) {
        return clothesMapper.getStockById(id);
    }

    @Override
    public PageInfo<Clothes> getClothesByPage(Integer pageNum, Integer pageSize) {
        if(pageNum==null){
            pageNum=1;
        }
        if(pageSize==null){
            pageSize=20;
        }
        PageHelper.startPage(pageNum, pageSize);//第几页，每页几条数据
        List<Clothes> list = clothesMapper.getClothesList();
        return new PageInfo<>(list);
    }


}
